<?php
/**
 * file:Database.php
 * This file is part of J-Game.
 *
 * @link    https://www.f4soft.com
 * @document https://www.f4soft.com
 * @contact 173120209@qq.com
 * @autho   :jackliang
 */
namespace F4soft\library;

use F4soft\lib\Medoo;
use F4soft\lib\RedisUtils;

class Database {
    private static $instance;

    private static $instanceSlave;
    private static $redis;

    /**
     * @return Medoo
     */
    public static function getInstance() {
        if (self::$instance == null) {
            $config = require __DIR__ . "/../../conf/datebase.php";
            self::$instance = new Medoo($config['db']);
        }
        return self::$instance;
    }

    /**
     * @return Medoo
     */
    public static function getInstanceSlave() {
        if (self::$instanceSlave == null) {
            $config = require __DIR__ . "/../../conf/datebase.php";
            self::$instanceSlave = new Medoo($config['db2']);
        }
        return self::$instanceSlave;
    }

    /**
     * @return RedisUtils
     */
    public static function getRedis() {
        if (self::$redis == null) {
            $config = require __DIR__ . "/../../conf/datebase.php";
            echo json_encode($config['redis']) . PHP_EOL;
            self::$redis = RedisUtils::getInstance($config['redis']);
        }
        return self::$redis;
    }
}